<template>
    <!-- 新人领券弹窗 -->
    <div class="coupon-popup popup-container">
        <div class="popup toast text-center" @click.stop>
            <div class="top white-color">
                <div class="avatar" v-if="userInfo && userInfo.avatar">
                    <img :src="userInfo.avatar" />
                </div>
                <div class="hg-text">
                    送您
                </div>
                <div class="sm-text">
                    获得限量<span class="sp-text">{{totalCount}}</span>元代金券
                </div>
                <div class="tip sm-text">
                    {{info.shelf_life}}天后过期
                </div>
                <div class="go-btn nm-text" @click="toUseCoupon">
                    前往使用
                </div>
                <div class="close" @click="closePopup">
                    <i class="icon">&#xe80b;</i>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import {
    currency,
} from '@/lib/utils';
import {
    api,
} from '@/lib/api';

export default {
    name: 'NewbieCouponPop',
    props: {
        info: {
            type: Object,
            required: true,
        },
        userInfo: {
            type: Object,
            required: true,
        },
    },
    computed: {
        totalCount() {
            return this.info ? currency(this.info.money) : 0;
        },
    },
    methods: {
        noop: {},
        /**
         * 关闭弹窗
         */
        closePopup() {
            this.$emit('click-close');
        },
        /**
         * 获取新人券
         */
        toUseCoupon() {
            if (this.info.type === 'good') {
                api.navigateTo({
                    url: '/pages/product_detail/main',
                    query: {
                        product_id: this.info.link_id,
                    },
                });
            } else if (this.info.type === 'package') {
                api.navigateTo({
                    url: '/pages/pkg_detail/main',
                    query: {
                        pkg_id: this.info.link_id,
                    },
                });
            }
            this.closePopup();
        },
    },
};
</script>

<style lang="less">
@import "../../lib/style/mixins.less";

.coupon-popup {
    .popup {
        width: 302px;
        height: 444px;
        border-radius: 14rpx;
        background-color: #A94237;
        overflow: hidden;
        .top {
            position: relative;
            box-sizing: border-box;
            height: 300px;
            padding-top: 140rpx;
            border-radius: 0 0 40% 40%;
            background-color: #C34C3D;
            .avatar {
                text-align: center;
                image {
                    width: 46px;
                    height: 46px;
                    border-radius: 50%;
                }
            }
            .tip {
                color: #FF9D94;
            }
        }
        .go-btn {
            position: absolute;
            width: 100px;
            height: 100px;
            line-height: 100px;
            left: 50%;
            bottom: -50px;
            transform: translateX(-50%);
            border-radius: 50%;
            background-color: #FFA943;
            text-align: center;
        }
        .close {
            position: absolute;
            top: 10rpx;
            left: 10rpx;
            font-size: 44rpx;
            color: #A54133;
        }
        .nm-text {
            font-size: 36rpx;
        }
        .sm-text {
            font-size: 28rpx;
        }
        .hg-text {
            font-size: 56rpx;
        }
        .sp-text {
            font-size: 96rpx;
        }
    }
}
</style>
